<template>
  <div class="goods-modal">
    <el-dialog v-model="dialogVisible" title="添加商品" width="30%" center>
      <el-form :model="formModal" label-width="70px">
        <el-form-item label="商品名称" prop="name">
          <el-input v-model="formDataVal.name" placeholder="请输入商品名称"></el-input>
        </el-form-item>
        <el-form-item label="原价格">
          <el-input v-model="formDataVal.oldPrice" placeholder="请输入原价格"></el-input>
        </el-form-item>
        <el-form-item label="新价格">
          <el-input v-model="formDataVal.newPrice" placeholder="请输入新价格"></el-input>
        </el-form-item>
        <el-form-item label="描述信息">
          <el-input v-model="formDataVal.desc" placeholder="请输入描述信息"></el-input>
        </el-form-item>
        <el-form-item label="状态">
          <el-input v-model="formDataVal.status" placeholder="请选择状态"></el-input>
        </el-form-item>
        <el-form-item label="图片">
          <el-input v-model="formDataVal.imgUrl" placeholder="请输入描述信息"></el-input>
        </el-form-item>
        <el-form-item label="地址">
          <el-input v-model="formDataVal.address" placeholder="请输入地址"></el-input>
        </el-form-item>
        <el-form-item label="收藏数量">
          <el-input v-model="formDataVal.favorCount" placeholder="请输入收藏数量"></el-input>
        </el-form-item>
        <el-form-item label="销售数量">
          <el-input v-model="formDataVal.saleCount" placeholder="请输入销售的数量"></el-input>
        </el-form-item>
        <el-form-item label="库存数量">
          <el-input v-model="formDataVal.inventoryCount" placeholder="请输入库存数量"></el-input>
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="dialogVisible = false">取消</el-button>
          <el-button type="primary" @click="ConfirmClick"> 确认 </el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script setup lang="ts">
import useProductStore from '@/store/modules/product'
import type { ElForm } from 'element-plus'
import { ref, reactive } from 'vue'

const productStore = useProductStore()

const dialogVisible = ref(false)

const formModal = ref<InstanceType<typeof ElForm>>()

// 绑定数据
const formDataVal = reactive({
  name: '',
  oldPrice: '',
  newPrice: '',
  desc: '',
  status: '',
  imgUrl: '',
  inventoryCount: '',
  saleCount: '',
  favorCount: '',
  address: ''
})

function setDialogVisible() {
  dialogVisible.value = true
}
// 点击了确定的操作
function ConfirmClick() {
  dialogVisible.value = false
  productStore.fetchNewProductData(formDataVal)
}
defineExpose({
  setDialogVisible
})
</script>

<style lang="less" scoped>
.goods-modal {
  h2 {
    color: red;
  }
}
</style>
